package com.qys.livesMall.system.controller.sys;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.model.dto.app.SysConfigSaveReq;
import com.qys.livesMall.system.model.dto.sys.SysConfigQuery;
import com.qys.livesMall.system.model.entity.H2SysConfig;
import com.qys.livesMall.system.model.vo.app.SysConfigGroupVO;
import com.qys.livesMall.system.model.vo.sys.H2SysConfigVO;
import com.qys.livesMall.system.service.IH2SysConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author caoz
 * @since 2023-04-20
 */
@Tag(name = "后台管理-平台参数配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("/h2-sys-config")
public class H2SysConfigController {

    @Autowired
    private IH2SysConfigService sysConfigService;

    @Operation(description = "添加平台参数配置")
    @PostMapping("/add")
    public R<?> add(@RequestBody H2SysConfigVO params) {
        sysConfigService.add(params);
        return R.ok();
    }

    @Operation(description = "修改平台参数配置")
    @PostMapping("/put")
    public R<?> put(@RequestBody H2SysConfigVO params) {
        sysConfigService.put(params);
        return R.ok();
    }

    @Operation(description = "平台参数配置分页查询")
    @PostMapping("/pageList")
    public R<Page<?>> pageList(@RequestBody SysConfigQuery query) {
        return R.ok(sysConfigService.pageList(query));
    }

    @Operation(description = "删除平台参数配置")
    @DeleteMapping("/del/{id}")
    public R<?> del(@PathVariable Integer id) {
        sysConfigService.removeById(id);
        return R.ok();
    }

    @Operation(description = "平台配置分组列表")
    @PostMapping("/listGroup")
    public R<List<SysConfigGroupVO>> listGroup() {
        return R.ok(sysConfigService.listGroup());
    }

    @Operation(description = "通过分组id查询配置")
    @PostMapping("/listConfigByGroup/{groupId}")
    public R<List<H2SysConfig>> listConfigByGroup(@PathVariable("groupId") int groupId) {
        return R.ok(sysConfigService.listConfigByGroup(groupId));
    }

    @Operation(description = "表单数据批量保存接口")
    @PostMapping("/save")
    public R<?> save(@RequestBody SysConfigSaveReq data) {
        return R.ok(sysConfigService.formSave(data));
    }
}
